#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;
int n,m,L,V,d[MAXN],v[MAXN],a[MAXN],p[MAXN];
int l[MAXN],r[MAXN];
int tree[1000005];
bool flag[MAXN];

int lowbit(int x){return x&(-x);}

void update(int x,int k){
    for(;x<=L;x+=lowbit(x)) tree[x]+=k;
}

int sum(int x)
{
    int ans=0;
    for(;x;x-=lowbit(x)) ans+=tree[x];
    return ans;
}

bool check(int x,int y){
    if(sum(y)-sum(x-1)>0) return true;
    else return false;
}

void solve()
{
    memset(tree,0,sizeof(tree));
    memset(flag,0,sizeof(flag));

    scanf("%d%d%d%d",&n,&m,&L,&V);
    int cnt=0,len=0;
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&d[i],&v[i],&a[i]);
        if(a[i]==0){
            if(v[i]>V) flag[i]=true,l[i]=d[i],r[i]=L,cnt++;
        }
        else if(a[i]>0){
            if(v[i]>V) flag[i]=true,l[i]=d[i],r[i]=L,cnt++;
            else if(v[i]*v[i]+2*a[i]*(L-d[i])>V*V) flag[i]=true,l[i]=(V*V-v[i]*v[i])/(2*a[i])+1,r[i]=L,cnt++;
        }
        else{
            if(v[i]>V){
                flag[i]=true,l[i]=d[i],cnt++;
                if(-1*v[i]*v[i]+d[i]*2*a[i]<2*a[i]*L&&v[i]*v[i]+2*a[i]*(L-d[i])>V*V) r[i]=L;
                else if((V*V-v[i]*v[i])%(2*a[i])==0) r[i]=(V*V-v[i]*v[i])/(2*a[i])-1+d[i];
                else r[i]=(V*V-v[i]*v[i])/(2*a[i])+d[i];
            }
        }
    }

    for(int i=1;i<=m;i++){
        scanf("%d",&p[i]);
        update(p[i],1);
    }

    int ans=0;
    for(int i=1;i<=n;i++){
        if(flag[i]&&check(l[i],r[i])) ans++;
    }
    printf("%d ",ans);

    ans=0;
    sort(p+1,p+m+1);
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(flag[j]&&check(l[j],r[j])){
                update(p[i],-1);
                if(!check(l[j],r[j])){
                    update(p[i],1);
                    break;
                }
                update(p[i],1);
            }
            if(j==n){
                ans++;
                update(p[i],-1);
            }
        }
    }
    printf("%d\n",ans);
}

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);

    int t;
    scanf("%d",&t);
    while(t--) solve();
    return 0;
}